package com.zlm.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.naming.AuthenticationException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: 郑力铭
 * @Date: Create in 2019-11-10.
 */
@Controller
public class RouterController {


    @RequestMapping({"/","/index"})
    public String index(){

        return "index";
    }

    @RequestMapping("/toLogin")
    public String toLogin(){
        return "login";
    }

    @RequestMapping("/add")
    public String add(){
        return "add";
    }

    @RequestMapping("/update")
    public String update(){
        return "update";
    }

    @RequestMapping("/login/error")
    public void errorLogin(HttpServletRequest request, HttpServletResponse response){
        AuthenticationException e = (AuthenticationException) request.getSession().getAttribute("SPRING_SECURITY_LAST_EXCEPTION");
        try {
            response.getWriter().write(e.toString());
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }


}
